package com.example.demo.response;

import com.example.demo.exception.ErrorCode;
import lombok.Data;

@Data
public class Response<T> {

    private Integer status;

    private String msg;

    private T data;

    public static Response ok() {
        return (new Response()).status(ErrorCode.OK.getCode()).msg(ErrorCode.OK.getMessage());
    }


    public static Response failed() {
        return (new Response()).status(ErrorCode.FAIL.getCode()).msg(ErrorCode.FAIL.getMessage());
    }

    private Response msg(String message) {
        this.msg = message;
        return this;
    }

    private Response status(int code) {
        this.status = code;
        return this;
    }

    public Response data(T data) {
        this.data = data;
        return this;
    }

}